package com.example.yuejianapp14.Activity.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejianapp14.Activity.Activity.TieziInfoActivity;
import com.example.yuejianapp14.Activity.JavaBean.Tiezi;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by jason_lin on 2017/10/20.
 */

public class TieziAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Tiezi> mDataList;
    private LayoutInflater mLayoutInflater;

    public TieziAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.tiezicard,parent,false);
        return new ViewHolder(v);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Tiezi entity = (Tiezi) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.tiezi_time.setText(entity.getTtime());

        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/tieziphoto/"+entity.getTpicture()).into(viewHolder.tiezi_pic);
        // viewHolder.news_stars.setRating(Float.parseFloat(entity.get("news_stars").toString()));
        // viewHolder.news_thumb.setIIntegemageResource(r.parseInt(entity.get("news_thumb").toString()));
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,TieziInfoActivity.class);
                intent.putExtra("tid",entity.getTid());
                intent.putExtra("t_img",entity.getTpicture());
                intent.putExtra("uid",entity.getUid());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView tiezi_pic;
        TextView tiezi_time;
        LinearLayout tiezi_container;

        public ViewHolder(View itemView) {
            super(itemView);
            tiezi_time = (TextView) itemView.findViewById(R.id.tiezi_time);
            tiezi_pic = (ImageView) itemView.findViewById(R.id.tiezi_pic);
            tiezi_container = (LinearLayout) itemView.findViewById(R.id.tiezi_container);
        }
    }
}
